package com.xms.consumers.form;

import com.xms.core.exception.XmsException;
import com.xms.form.event.CreateDefaultFormEvent;
import com.xms.form.service.ISystemFormCreaterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.sql.SQLException;

/**
 * <p>
 * 事件消费者之创建默认表单
 * </p>
 *
 * @author migo
 * @since 2021/9/29
 */
@Service
public class CreateDefaultFormConsumer {
    private ISystemFormCreaterService _systemFormCreaterService;

    @Autowired
    public CreateDefaultFormConsumer(ISystemFormCreaterService systemFormCreaterService) {
        _systemFormCreaterService = systemFormCreaterService;
    }

    @Async
    @EventListener
    public void handleEvent(CreateDefaultFormEvent eventMessage) throws XmsException, SQLException {
        _systemFormCreaterService.createDefaultForm(eventMessage.source);
    }
}
